package com.adou.d12;

public class ExceptionTest {
    public static void main(String[] args) {
        try {
            saveAge(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }


        // 编译时异常
        try {
            saveAge2(100);
        } catch (AgeException2 e) {
            e.printStackTrace();
        }
    }

    public static void saveAge(int age){
        if(age > 0 && age < 160) {
            System.out.println("你输入的年龄：" + age);
        } else {
            // 用一个异常类定义
            // 跑出去异常对象
            throw new AgeException("age is illegal, you age is " + age);
        }
    }

    public static void saveAge2(int age) throws AgeException2{
        if(age > 0 && age < 160) {
            System.out.println("你输入的年龄：" + age);
        } else {
            // 用一个异常类定义
            // 跑出去异常对象
            throw new AgeException2("age is illegal, you age is " + age);
        }
    }
}
